﻿using System;
using System.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using ContainerHost.ServiceModel;

namespace ContainerHost.Unity
{
    /// <summary>
    /// IContainer implementation for Unity
    /// </summary>
    public class UnityContainerFacade : IContainer, IDisposable
    {
        private UnityContainer _container;

        /// <summary>
        /// Initializes a new instance of the UnityContainerWrapper class.
        /// </summary>
        public UnityContainerFacade()
        {
            _container = new UnityContainer();

            //configure container 
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(_container);
        }
        #region IContainer Members

        public object Resolve(Type t)
        {
            return _container.Resolve(t);
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            if (_container != null)
            {
                _container.Dispose();
            }
        }

        #endregion
    }
}
